package com.lanyuan.a.service.union;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.lanyuan.a.bean.Article;
import com.lanyuan.a.service.ArticleService;

@Service("adminService")
public class AdminService {
	@Resource
	ArticleService articleService;
	public List<Article> updateTitle(List<Article> list){
		for(int i=0 ; i<list.size(); i++){
			Article at = list.get(i);
			list.get(i).setTitle(together(at.getId() , at.getTitle()));
		}
		return list;
	}
	public String together(int id , String title){
		String taga = "<a href='javascript:show("+id+")'>";
		taga += title;
		taga += "</a>";
		return taga;
	}
	
	public String saveArticle(String id , String title , String tag , String content){
		try{
			Article at;
			if(id != null){
				at = articleService.get(Integer.parseInt(id));
			}else{
				at = new Article();
			}
			at.setTag(tag);
			at.setTitle(title);
			at.setContent(content);
			at.setCreatetime(new Date());
			articleService.saveOrUpdate(at);
		}catch(Exception e){
			e.printStackTrace();
			return "error";
		}
		return "success";
	}
}
